class NormalDistribution:
    def __init__(self):
        self.ini_NDlist = [1]
        self.get_p_list = []

    def NDnext(self, ini_NDlist):
        p_NDlist = ini_NDlist.copy()
        p_NDlist.insert(0, 0)
        ini_NDlist.append(0)
        NDlist = []
        for i in range(len(ini_NDlist)):
            NDnum = ini_NDlist[i] + p_NDlist[i]
            NDlist.append(NDnum)
        return NDlist

    def ND_start(self, max_times):
        for i in range(max_times):
            self.ini_NDlist = self.NDnext(self.ini_NDlist)
            # print(self.ini_NDlist)
        for ND_values in self.ini_NDlist:
            # print(ND_values,end='\t')
            print('', end='')
        self.get_p_list = self.ini_NDlist


def __test():
    for i in range(int(input("测试次数:"))):
        ND = NormalDistribution()
        ND.ND_start(i)
        value = 2 ** i
        test_value = 0
        for v in ND.ini_NDlist:
            test_value += v
        print((True if test_value == value else False))


def trans_p(ini_NDlist):
    '''向概率转换'''
    dmt = 2 ** (len(ini_NDlist) - 1)
    p_NDlist = []
    for value in ini_NDlist:
        p = float(value / dmt)
        p_NDlist.append(p)
    return p_NDlist


def mab_show(p_NDlist):
    plt.ion()
    plt.figure(1)
    while 1:
        ND_x = list(range(len(p_NDlist)))
        ND_y = p_NDlist
        print(p_NDlist)
        '''作图开始'''
        plt.plot(ND_x, ND_y)
        plt.pause(0.1)


def start():
    '''run'''
    n = int(input("请输入分布次数:"))
    ND = NormalDistribution()
    ND.ND_start(n)
    p_NDlist = trans_p(ND.get_p_list)
    mab_show(p_NDlist)


from pylab import *

# 解决中文无法显示问题
mpl.rcParams['font.sans-serif'] = ['SimHei']


def dym_gh():
    plt.ion()
    plt.figure(1)
    n = 0
    while 1:
        n += 1
        ND = NormalDistribution()
        ND.ND_start(n)
        p_NDlist = trans_p(ND.get_p_list)
        ND_x = list(range(len(p_NDlist)))
        ND_y = p_NDlist
        print(p_NDlist)
        '''作图开始'''
        plt.cla()
        plt.xlim(0, len(p_NDlist))  # 设置x轴长度范围
        plt.ylim(0, 0.12)  # 设置y轴长度范围
        plt.title('正态分布')  # 设置标题
        plt.xlabel('X')  # 设置x轴标签
        plt.ylabel('P(X)')  # 设置y轴标签
        plt.plot(ND_x, ND_y)
        plt.pause(0.01)


dym_gh()
